<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <script>
    //用来合并对象 把第二个对象合并给第一个对象 返回第一个对象
    //Object.assign(目标对象,源对象1,源对象2,...)
    const dog={name:'dog',age:1}
    const cat={name1:'cat',age1:2}
    console.log(Object.assign(cat,dog));
    console.log(cat===Object.assign(cat,dog));
    console.log({...dog,...cat});
    //可以合并多个对象
    console.log(Object.assign({},dog,cat));
    //基本数据类型作为源对象 先转化为对象，在合并
    console.log(Object.assign({},undefined));
    console.log(Object.assign({},null));
    console.log(Object.assign({},true));
    console.log(Object.assign({},1));
    console.log(Object.assign({},'abc'));
    //同名属性的替换 后面的直接覆盖前面的
    const dog1={name:'dog',age:1}
    const cat1={name:'cat',age:2}
    console.log(Object.assign(cat,dog));
    //合并默认参数和用户参数
    const logUser=userOptions=>{
      const DEFAULTS={name:'a',age:18,sex:'male'}
      const options=Object.assign({},DEFAULTS,userOptions)
      console.log(options);
    }
    logUser({})
    logUser({heigt:'180'})

  </script>
</body>
</html>